package com.atguigu.shiro.service.impl;

import com.atguigu.shiro.entity.User;
import com.atguigu.shiro.mapper.UserMapper;
import com.atguigu.shiro.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * className: UserServiceImpl
 * description:
 * date: 2024/6/18-10:25
 * <p>
 * project: shiro
 * package: com.atguigu.shiro.service.impl
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    /**
     * 用户登录
     *
     * @param name {@link  String}
     * @return {@link User}
     */
    @Override
    public User getUserInfoByName(String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name", name);
        return this.getOne(wrapper);
    }


    /**
     * 获取用户的角色信息
     *
     * @param principal {@link String}
     * @return {@link List<String>}
     */
    @Override
    public List<String> getUserRoleInfo(String principal) {
        return baseMapper.getUserRoleInfoMapper(principal);
    }

    /**
     * 获取用户的权限信息
     *
     * @param roles {@link List<String>}
     * @return {@link List<String>}
     */
    @Override
    public List<String> getUserPermissionInfo(List<String> roles) {
        return baseMapper.getUserPermissionInfoMapper(roles);
    }
}
